/**
 * 处理路由滚动视图 scrollBehavior
 * @returns {(object|boolean)} Scroll position or `false`
 */
export async function scrollBehavior(to, from, savedPosition) {
  const behavior = 'smooth'
  if (savedPosition) {
    return { ...savedPosition, behavior }
  }

  if (to.hash) {
    return { el: decodeURI(to.hash), behavior }
  }

  // 检测路由meta是否存在scrollToTop =  false的
  if (to.matched.some((m) => m.meta.scrollToTop === false)) {
    return false
  }

  // 默认切换路由跳转顶部
  return { left: 0, top: 0, behavior }
}
